package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        System.out.println("请输入书名");
        Scanner in =new Scanner(System.in);
        String name = in.nextLine();
        for (int i = 0; i < bookList.getBookSize(); i++) {
            Book book = bookList.getBook(i);
            if(name.equals(book.getName())) {
                bookList.putBook(i, bookList.getBook(i+1));
            }
            int pos = bookList.getBookSize();
            bookList.setBookSize(pos-1);
            System.out.println("删除成功");
            return ;
        }
        System.out.println("未找到该书");
    }
}
